package com.zhou.juc.test09_Interview;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouyanxiang
 * @create 2020-08-2020/8/15-12:32
 */
public class T01_WithOutVolatile {

    List lists = new ArrayList();

    public void add(Object o){
        lists.add(o);
    }

    public int size(){
        return lists.size();
    }

    public static void main(String[] args) {

        T01_WithOutVolatile t = new T01_WithOutVolatile();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                t.add(i);
                System.out.println(" add " + i);
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1").start();

        new Thread(()->{
            while(true){
                if (t.size() == 5){
                    break;
                }
            }
            System.out.println("=======T2  end======");
        },"t2").start();
    }

}
